package com.nulldev.util.gui.swingAPI.demos;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTree;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import com.nulldev.util.gui.themeAPI.ThemeAPI;
import com.nulldev.util.gui.themeAPI.ThemeAPI.ThemingOptions;

public class SimpleThemingDemo extends JFrame {
	private static final long serialVersionUID = 951360954504012783L;
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SimpleThemingDemo frame = new SimpleThemingDemo();
					frame.setVisible(true);
					ThemeAPI.applySystemSwingTheme(frame, ThemingOptions.APPLY_SYSTEM_FONT);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SimpleThemingDemo() {
		setTitle("nullUtil 3.x: ThemeAPI Demo");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);

		JPanel panel = new JPanel();
		tabbedPane.addTab("Simple Text Demo", null, panel, null);

		JLabel lblHelloWorld = new JLabel("Hello world!");

		JLabel lblMultiline = new JLabel("<html>Multi-line<br>String!</html>");

		JLabel lblTimeForA = new JLabel("Time for a big label!");
		lblTimeForA.setFont(lblTimeForA.getFont().deriveFont(32f));
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup().addContainerGap().addGroup(
						gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblHelloWorld).addComponent(lblMultiline).addComponent(lblTimeForA))
						.addContainerGap(327, Short.MAX_VALUE)));
		gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup().addContainerGap().addComponent(lblHelloWorld).addGap(18).addComponent(lblMultiline)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(lblTimeForA).addContainerGap(148, Short.MAX_VALUE)));
		panel.setLayout(gl_panel);

		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("Tree Demo", null, panel_1, null);
		panel_1.setLayout(new BorderLayout(0, 0));

		JTree tree = new JTree();
		tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Tree Demo") {
			private static final long serialVersionUID = 1L;

			{
				DefaultMutableTreeNode node_1;
				DefaultMutableTreeNode node_2;
				node_1 = new DefaultMutableTreeNode("a");
				node_2 = new DefaultMutableTreeNode("b");
				node_2.add(new DefaultMutableTreeNode("c"));
				node_1.add(node_2);
				add(node_1);
				node_1 = new DefaultMutableTreeNode("b");
				node_1.add(new DefaultMutableTreeNode("slight longer text!"));
				node_1.add(new DefaultMutableTreeNode("another element"));
				node_1.add(new DefaultMutableTreeNode("yet another element"));
				add(node_1);
				node_1 = new DefaultMutableTreeNode("c");
				node_1.add(new DefaultMutableTreeNode("_even more fun!_"));
				add(node_1);
				node_1 = new DefaultMutableTreeNode("d");
				node_1.add(new DefaultMutableTreeNode("HERE I AM STUCK WITH CAPS LOCK"));
				add(node_1);
			}
		}));
		panel_1.add(tree, BorderLayout.CENTER);
	}
}
